package com.ts_xiaoa.ts_base.utils

import android.graphics.Color

/**
 * create by ts_xiaoA on 2020-08-28 09:12
 * email：443502578@qq.com
 * desc：
 */
/**
 * 计算渐变颜色中间色值
 *
 * @param startColor 起始颜色
 * @param endColor   结束颜色
 * @param ratio      百分比，取值范围【0~1】
 * @return 颜色值
 */
fun getColor(startColor: Int, endColor: Int, radio: Float): Int {
    val redStart: Int = Color.red(startColor)
    val blueStart: Int = Color.blue(startColor)
    val greenStart: Int = Color.green(startColor)
    val redEnd: Int = Color.red(endColor)
    val blueEnd: Int = Color.blue(endColor)
    val greenEnd: Int = Color.green(endColor)
    val red = (redStart + ((redEnd - redStart) * radio + 0.5)).toInt()
    val greed = (greenStart + ((greenEnd - greenStart) * radio + 0.5)).toInt()
    val blue = (blueStart + ((blueEnd - blueStart) * radio + 0.5)).toInt()
    return Color.argb(255, red, greed, blue)
}

//0xff123456的颜色值
val Long.color: Int
    get() = this.toInt()